package cn.bai.mvc;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Created by Admin on 12/22 0022.
 */
public class JDBCUtil {
    public  static Connection getConnection()throws Exception{
        Properties info=new Properties();
        InputStream in=
                JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
        info.load(in);
        String driverClass=info.getProperty("driverClass");
        String url=info.getProperty("url");
        String username=info.getProperty("user");
        String password=info.getProperty("password");
        info.put("username",username);
        info.put("password",password);
        Class.forName(driverClass);
        Connection connection=DriverManager.getConnection(url,info);
        return connection;

    }

    public static void release(Connection connection){
        if(connection!=null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
